/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","fu/app/comm/comm"],function($,$bb,$comm){
	var servers = {};
	var URL = $bb.baseUrl("followup");

	/* 请求顶部和底部的统计数据 */
	servers.ajaxStatis = function(callback){
		$bb.ajax({
			url: URL + "followup/service/patient/patientQueueStatisticsQuery",
			data:JSON.stringify({
				data : {
					"schemeBusiType":1
				}
			}),
			success: function(data){
				if(data.success){
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求统计数据出错！");
				}	
			}
		});
	}; 
	/* 请求队列selectQueue */
	servers.ajaxQueue = function(callback){
		$bb.ajax({
			url: URL + "followup/service/queue/followQueueListQuery",
			success: function(data){
				if(data.success){
					callback(data.data.rows);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求队列出错！");
				}
			}
		});
	}
	/* 请求今日门诊记录 */
	servers.ajaxPatientsOperate = function(params,callback){
		$bb.ajax({
			url: URL + "followup/service/patient/patientOperateListQuery",
			data:JSON.stringify({
				data : params
			}),
			success: function(data){
				if(data.success){
					callback(data.data.rows);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求今日门诊记录出错！");
				}	
			}
		});
	}
	/* 请求全部患者 */
	servers.ajaxPatientsQueue = function(params,callback){
		$bb.ajax({
			url: URL + "followup/service/patient/patientQueueListQuery",
			data:JSON.stringify({	
				data : params
			}),
			success: function(data){
				if(data.success){
					callback(data.data,params);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求窗口期随访患者出错！");
				}	
				$("#patientOperateListQuery").css({"height": $("#windowBabyList").height() + $(".ws-bottom-left-bottom").height() + 'px'});
			}
		});
	}

	/**
	 * 获取当前时间所在的位置的索引
	 * @param  {[num]} week [当前时间是第几周]
	 * @return {[type]}      [进度]
	 */
	var getCurrDateIndex = function(week){
		if( week < 12 ){
			return "noStart";
		}else if( week == 12 ){
			return 0;
		}else if( week < 16 ){
			return 1;
		}else if( week < 20 ){
			return 2;
		}else if( week < 24 ){
			return 3;
		}else if( week < 28 ){
			return 4;
		}else if( week < 32 ){
			return 5;
		}else if( week < 35 ){
			return 6;
		}else if( week == 36 ){
			return 7;
		}else if( week == 37 ){
			return 8;
		}else if( week < 42 ){
			return 9;
		}else {
			return "overdue";
		}
	}
	/* 处理数据 */
	servers.handlePatientsQueue = function(list){
		var len = 11; // 默认10次随访+建档
		var curDate = $comm.getCurTime().date;
		for (var i = 0; i < list.length; i++) {
			var week = parseInt( $comm.dateDiff(list[i].Pub13x00001,curDate).days / 7 );
			var currDateIndex = getCurrDateIndex(week);
			// "0":未到时间的,"1":已完成,"2":过期的,"3":当前时间
			if( currDateIndex == "noStart" ){
				list[i].progressArr = ["1","0","0","0","0","0","0","0","0","0","0"];
			}else if( currDateIndex == "overdue" ){
				list[i].progressArr = ["1","2","2","2","2","2","2","2","2","2","2"];
			}else{
				list[i].progressArr = [];
				list[i].progressArr[0] = "1"
				for (var j = 1; j < len; j++) {
				 	if( j < currDateIndex ){
				 		list[i].progressArr[j] = "2";
				 	}else if( j == currDateIndex ){
				 		list[i].progressArr[j] = "3";
				 	}else{
				 		list[i].progressArr[j] = "0";
				 	}
				 } 
			}
		}
		return list;
	}
	return servers;
});